import request from "@/utils/request";

/**
 * 地址接口参数
 */
export interface AddressParams {
	id?: number;
	name: string;
	phone: string;
	province: string;
	city: string;
	district: string;
	detail: string;
	isDefault?: boolean;
}

/**
 * 获取地址列表
 */
export function getAddressList() {
	return request.get("/api/addresses");
}

/**
 * 获取地址详情
 */
export function getAddressDetail(id: number) {
	return request.get(`/api/addresses/${id}`);
}

/**
 * 新增地址
 */
export function addAddress(data: AddressParams) {
	return request.post("/api/addresses", data);
}

/**
 * 更新地址
 */
export function updateAddress(id: number, data: AddressParams) {
	return request.patch(`/api/addresses/${id}`, data);
}

/**
 * 删除地址
 */
export function deleteAddress(id: number) {
	return request.delete(`/api/addresses/${id}`);
}

/**
 * 设置默认地址
 */
export function setDefaultAddress(id: number) {
	return request.patch(`/api/addresses/default/${id}`);
}
